<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="../assets/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="../assets/js/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../assets/css/login.css">
    <title>No.2商城-注册成功</title>
    <script>
        function registerCart(uid) {
            $.ajax({
                async: false,//取消异步执行，为同步执行。进而被其他方法调用
                url: "http://localhost:80/phalapi/public/index.php?s=App.Cart.insertCartByUid",
                type: "get",
                data: {
                    "user_id": uid
                },
                dataType: "JSON",
                success: function (re) {
                    var id = re.data.id;
                    console.log("id:" + id)
                },
                error: function (msg) {
                    alert("错误信息：" + msg);
                }
            })
        }

        $(function () {
            $.ajax({
                url: "http://localhost:80/phalapi/public/index.php?s=App.User.insertUserInfo",
                type: "POST",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify({
                    'username': '<?php echo $_GET['un'] ?>',
                    "password": '<?php echo $_GET['pd'] ?>',
                    "email": '<?php echo $_GET['em'] ?>',
                    "gender": '<?php echo $_GET['sx'] ?>'
                }),
                dataType: "JSON",
                success: function (result) {
                    // console.log(result.data.id)//返回新增id
                    registerCart(result.data.id);//注册成功调用接口创建该用户的购物车
                },
                error: function (msg) {
                    alert("错误信息：" + msg);
                }
            })
        })
    </script>
</head>
<body>
<div class="regist">
    <div class="regist_center">
        <div class="regist_top">
            <div class="left fl"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;会员注册</div>
            <div class="right fr">
                <a href="../index.html" target="_black">No.2商城</a>
            </div>
            <div class="clear"></div>
            <div class="xian center"></div>
        </div>
        <div style="margin-top: 80px;margin-left: 100px;">
            <p class="text-info" style="font-size: 20px;">注册成功</p>
            <a class="btn btn-default" href="../index.php" target="_blank">返回主页</a>
        </div>
    </div>
</div>
</body>
</html>